/**
 * Created by zhangsong on 2017/12/7.
 */
var params = new Object();
var url = path + "/system/cronmonitor/list";


$(function () {
    //设置AjaxLoading
    setAjaxLoading();
    var grid = $("#tt");
    initGrid(grid);
});


//初始化表格和数据
function initGrid(grid) {
    var columns = [
        {field: "cronMonitorId", title: "ID", hidden: true, align: "left", sortable: false, resizable: true, width: 80},
        {
            field: "jobName",
            title: "任务名称",
            align: "left",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 130
        },
        {
            field: "jobGroup",
            title: "任务分组",
            align: "left",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 120
        },
        {
            field: "entryId",
            title: "执行任务的节点",
            align: "left",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 120
        },
        {
            field: "jobState",
            title: "任务状态",
            align: "center",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 80

        },


        {
            field: "executeTime",
            title: "调用时间",
            align: "center",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 200,
            formatter: function (value) {
                var date = new Date();
                date.setTime(value);
                var y = date.getFullYear();
                var M = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours();
                var m = date.getMinutes();
                var s = date.getSeconds();
                if (M < 10) {
                    M = "0" + M;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (m < 10) {
                    m = "0" + m;
                }
                if (s < 10) {
                    s = "0" + s;
                }
                return y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
            }
        },

        {
            field: "endTime",
            title: "任务结束时间",
            align: "center",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 150,
            formatter: function (value) {
                if (value == null) {
                    return;
                }
                var date = new Date();
                date.setTime(value);
                var y = date.getFullYear();
                var M = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours();
                var m = date.getMinutes();
                var s = date.getSeconds();
                if (M < 10) {
                    M = "0" + M;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (m < 10) {
                    m = "0" + m;
                }
                if (s < 10) {
                    s = "0" + s;
                }
                return y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
            }
        },
        {
            field: "nextExecuteTime",
            title: "下次调用时间",
            align: "center",
            halign: "center",
            sortable: false,
            resizable: true,
            width: 150,
            formatter: function (value) {
                if (value == null) {
                    return;
                }
                var date = new Date();
                date.setTime(value);
                var y = date.getFullYear();
                var M = date.getMonth() + 1;
                var d = date.getDate();
                var h = date.getHours();
                var m = date.getMinutes();
                var s = date.getSeconds();
                if (M < 10) {
                    M = "0" + M;
                }
                if (d < 10) {
                    d = "0" + d;
                }
                if (h < 10) {
                    h = "0" + h;
                }
                if (m < 10) {
                    m = "0" + m;
                }
                if (s < 10) {
                    s = "0" + s;
                }
                return y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
            }
        }
    ];

    initPageGrid(grid, params, url, columns, "");
   // getPage(grid, params, url);
    btnReset();
}

//查询按钮
function btnQuery() {
    params.jobName = $("#jobName").val();
    params.jobGroup = $("#jobGroup").val();
    params.jobState = $("#jobState").val();
    params.executeTimeStart = $("#executeTimeStart").datebox("getValue");
    params.executeTimeEnd = $("#executeTimeEnd").datebox("getValue");
    params.endTimeStart = $("#endTimeStart").datebox("getValue");
    params.endTimeEnd = $("#endTimeEnd").datebox("getValue");
    params.nextExecuteTimeStart = $("#nextExecuteTimeStart").datebox("getValue");
    params.nextExecuteTimeEnd = $("#nextExecuteTimeEnd").datebox("getValue");
    var grid = $("#tt");
    getPage(grid, params, url);

}

//重置按钮
function btnReset() {
    var curr_time = new Date();
    $("#jobName").val('');
    $("#jobGroup").val('');
    $("#jobState").val('');

    $('#executeTimeStart').datebox("setValue", myformattery());
    $('#executeTimeEnd').datebox("setValue", myformatter());
    $('#endTimeStart').datebox("setValue", "");
    $('#endTimeEnd').datebox("setValue", "");
    $("#nextExecuteTimeStart").datebox("setValue", "");
    $("#nextExecuteTimeStart").datebox("setValue", "");
    btnQuery();

}
function myformattery() {
    var date = new Date();
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate() - 1;
    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}

function myformatter() {
    var date = new Date();
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}





